
import * as echarts from 'echarts'
import _ from 'lodash'
export const getOption = (datas) => {
    const barWidth = 20;
    return {

        //提示框
        tooltip: {
            trigger: "axis",
            show: "true",
            // axisPointer: {
            //     type: "cross",
            // },
            backgroundColor: 'rgba(0,0,0,0.65)',
            borderWidth: 0,
            textStyle: {
                color: "#fff"
            },
            formatter: function (params) {
                return params[0].name + '：' + params[0].value + ' 处';

            }
        },
        /**区域位置*/
        grid: {
            left: 0,
            right: 0,
            top: 30,
            bottom: 10,
            // heigth: 350,
            containLabel: true,
        },

        // legend: {
        //     data: ["草地生产力"],
        //     top: 20,
        //     textStyle: {
        //         color: "#ffffff",
        //         fontSize: 14,
        //     },
        //     icon: "circle",
        //     right: 20,
        //     // itemWidth: 16,
        //     // itemHeight: 12,
        //     // itemGap: 80,
        //     selectedMode: false,
        // },
        //X轴

        xAxis: {
            type: "category",
            data: datas.map(d => d.name),
            axisLine: {
                show: false,
                lineStyle: {
                    color: "#15205B",
                },
            },
            axisTick: {
                show: false,
            },
            splitLine: {
                show: false,
            },
            axisLabel: {
                margin: 15,
                overflow: "breakAll",
                // width: 20,
                textStyle: {
                    fontFamily: "Microsoft YaHei",
                    color: "#fff", // x轴颜色
                    fontWeight: "normal",
                    fontSize: "14",
                    lineHeight: 18,
                },
                rotate: 30,
                interval: 0, //标签设置为全部显示
                formatter: (value) => {
                    let v = '';
                    value.split('').forEach((str, i) => {
                        v = v + str
                        if (i === 3) {
                            v = v + '\n'
                        }
                    })
                    return v
                }
            },
        },
        yAxis: {
            name: '数量',
            // min: 0,
            // max: max,
            nameTextStyle: {
                align: "left",
                color: "rgba(101,198,231,0.7)",
                fontSize: 14,
            },
            type: "value",
            axisLine: {
                show: false,
                lineStyle: {
                    color: "#15205B",
                },
            },
            splitLine: {
                show: true,
                lineStyle: {
                    opacity: 0.2,
                    color: '#335971',
                    "type": "dashed"
                },
            },
            alignTicks: true,
            axisTick: {
                show: false,
            },
            axisLabel: {
                textStyle: {
                    color: "rgba(101,198,231,0.7)",
                    fontSize: 16,
                },
            },
        },
        series: [{
            name: '政府综合减灾资源',
            type: 'bar',
            stack: 'ttt',
            barWidth: barWidth,
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        {
                            offset: 0,
                            color: '#f6fe1d',
                        },
                        {
                            offset: 1,
                            color: '#feb009',
                        },
                    ]),
                }
            },
            label: {
                show: true,
                position: 'top',
                // "formatter": "{c}%"
                fontSize: 13,
                fontWeight: 'bold',
                // formatter:(args)=>{
                //     console.log(args)
                //     return args.value.toString().split('').join('\n')
                // }
                color: '#fff',
            },
            data: datas.map(d => d.value)
        },
        {
            z: 2,
            type: 'pictorialBar',
            data: datas.map(d => d.value),
            symbol: 'diamond',
            symbolOffset: [0, '50%'],
            symbolSize: [barWidth, barWidth * 0.5],
            itemStyle: {
                normal: {
                    color: '#feb009'
                }
            },
        },
        {
            z: 3,
            type: 'pictorialBar',
            symbolPosition: 'end',
            data: datas.map(d => d.value),
            symbol: 'diamond',
            symbolOffset: [0, '-50%'],
            symbolSize: [barWidth, barWidth * 0.5],
            itemStyle: {
                normal: {
                    borderWidth: 0,
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        {
                            offset: 0,
                            color: '#f6fe1d',
                        },
                        {
                            offset: 1,
                            color: '#feb009',
                        },
                    ]),

                }
            },
        },
        ],
    };
}